<template>
  <div>

    <!--加/减分-->
    <el-dialog
      :close-on-click-modal="false"
      :visible.sync="visibleNum"
      title="用户黑名单"
    >
      <el-form
        :model="dataForm"
        ref="dataForm"
        label-width="150px"
        :rules="rules"
      >
        <el-form-item label="是否永久冻结" prop='forbidRevenueStatus'>
          <el-radio-group v-model="dataForm.forbidRevenueStatus" @change="setForbidRevenueStatus">
            <el-radio :label="1">是</el-radio>
            <el-radio :label="2">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item v-if="dataForm.forbidRevenueStatus !== 1" label="请选择解冻时间" prop='releaseTime'>
          <el-date-picker
            popper-class = 'dingTime'
            v-model="dataForm.releaseTime"
            type="datetime"
            placeholder="选择解冻时间"
            @change="changeTime"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="冻结理由" prop="forbidRevenueReason">
          <el-input v-model="dataForm.forbidRevenueReason" placeholder="请输入冻结理由"  type="textarea" :rows="4"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
      <el-button @click="visibleNum = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
    </el-dialog>

  </div>
</template>

<script>
  export default {
    data() {
      return {
        visibleNum: false,
        dataForm: {
          forbidRevenueStatus: '',
          releaseTime: '',
          forbidRevenueReason: ''
        },
        fileLists: [],
        rules: {
          forbidRevenueStatus: [
            { required: true, message: '请选择是否永久冻结', trigger: 'blur' }
          ],
          releaseTime: [
            { required: true, message: '请选择解冻时间', trigger: 'blur' }
          ],
          forbidRevenueReason: [
            { required: true, message: '请输入冻结理由', trigger: 'blur' }
          ]
        },
      }
    },
    methods: {
      initData(id) {
        this.dataForm = {
          userId: id,
          forbidRevenueStatus: '',
          releaseTime: '',
          forbidRevenueReason: ''
        },
        this.visibleNum = true
      },
      changeTime () {
        if (new Date(this.dataForm.releaseTime).getTime() < new Date().getTime()) {
          this.dataForm.releaseTime = ''
          this.$message.error('所选时间要大于当前时间')
        }
      },
      setForbidRevenueStatus() {
        if(this.dataForm.forbidRevenueStatus == 2) {
          this.dataForm.releaseTime = ''
        }
      },
      // 表单提交
      dataFormSubmit() {
        if(this.dataForm.forbidRevenueStatus === 1) {
          // 永久冻结解冻时间随意赋值，跳过验证
          this.dataForm.releaseTime = '2200-01-01 00:00:00'
        }
        this.$refs["dataForm"].validate(valid => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/sale/saleRelation/forbidUserRevenue`),
              method: 'post',
              data: this.$http.adornData(this.dataForm)
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visibleNum = false
                    this.$emit('refresh')
                  }
                });
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      },
    }
  }
</script>
<style scoped>
  .noteContent{
    border: 1px solid #898989;
    border-radius: 6px;
    padding: 30px;
    height:400px;
    overflow-y: scroll;
  }
  .noteContent img{
    width: 100%!important;
    height: auto;
  }
</style>
